package com.hxiaoyi.cloud.controller;

import com.hxiaoyi.cloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * PaymentController
 * @author 黄敬意
 * @date 2022-02-09 21:43
 **/
@RestController
@Slf4j
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    /**端口号*/
    @Value("${server.port}")
    private String serverPort;

    /**ok*/
    @GetMapping(value = "/payment/hystrix/ok/{id}")
    public String paymentInfoOK(@PathVariable("id") Integer id) {
        String result = paymentService.paymentInfo_OK(id);
        log.info("-------返回的result为：" + result);
        return result;
    }

    /**超时*/
    @GetMapping(value = "/payment/hystrix/timeout/{id}")
    public String paymentInfoTimeOut(@PathVariable("id") Integer id) {
        String result = paymentService.paymentInfo_TimeOut(id);
        log.info("-------返回的超时result为：" + result);
        return result;
    }

    /**服务熔断*/
    @GetMapping(value = "/payment/circuit/{id}")
    public String paymentCircuitBreakerFallback(@PathVariable("id") Integer id) {
        String result = paymentService.paymentCircuitBreaker(id);
        log.info("-------返回的服务熔断的result为：" + result);
        return result;
    }
}
